// Copyright 2012. InMobi. All Rights reserved

package com.inmobi.sharedlock;

/**
 * Delegates its calls to another calculator.
 */
public class ThreadSafeCalculator2 implements AverageCalculator {

  private final AverageCalculator averageCalculator;

  public ThreadSafeCalculator2() {
    averageCalculator = new SimpleCalculator();
  }

  @Override
  public void addValue(long value) {
    synchronized (averageCalculator) {
      averageCalculator.addValue(value);
    }
  }

  @Override
  public double getAverage() {
    synchronized (averageCalculator) {
      return averageCalculator.getAverage();
    }
  }
}
